home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / mach / amiga / scsi9091.lzh / debugprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-24  |  2.0 KB  |  112 lines

  1.  
  2. #include <exec/types.h>
  3. #include <exec/execbase.h>
  4. #include <exec/nodes.h>
  5. #include <exec/resident.h>
  6. #include <exec/errors.h>
  7. #include <exec/semaphores.h>
  8. #include <libraries/expansionbase.h>
  9. #include <libraries/configvars.h>
  10. #include <devices/trackdisk.h>
  11.  
  12. /*
  13.  * Set SysBase to a local variable, that loads directly from 4 when it
  14.  * has to be reloaded
  15.  */
  16. #define PRIVATE
  17. #define BASE_EXT_DECL
  18. #define BASE_NAME (*(void **)4)
  19. #include <inline/exec.h>
  20. #undef PRIVATE
  21.  
  22. #ifdef DEBUG
  23.  
  24. #include "device.h"
  25.  
  26. extern struct MsgPort *CreatePort();
  27. extern void DeletePort(struct MsgPort *mp);
  28.  
  29. static inline int strcmp(char *s, char *d)
  30. {
  31.   while (*s && *s == *d) ++s, ++d;
  32.   return *s-*d;
  33. }
  34.  
  35. /* no more evil enforcer hits:-)) */
  36. struct MsgPort *
  37. myFindPort(char *name)
  38. {
  39.   struct MsgPort *mp, *np;
  40.   struct ExecBase *SysBase = *(struct ExecBase **)4;
  41.  
  42.   Forbid();
  43.   for (mp = (struct MsgPort *)SysBase->PortList.lh_Head;
  44.        np = (struct MsgPort *)mp->mp_Node.ln_Succ;
  45.        mp=np)
  46.     if (mp->mp_Node.ln_Name && !strcmp(mp->mp_Node.ln_Name, name)) break;
  47.   Permit();
  48.   
  49.   return np ? mp : 0;
  50. }
  51.  
  52. void
  53. dprintf(fmt, a0,a1,a2,a3,a4,a5,a6,a7)
  54.   char *fmt;
  55.   int a0,a1,a2,a3,a4,a5,a6,a7;
  56. {
  57.   struct MsgPort *mp, *op;
  58.   struct Message ms[2];
  59. #if 0
  60.   static struct SignalSemaphore ss;
  61.   static int sem_ok = 0;
  62. #endif
  63.   char *buf;
  64.  
  65. #if 0
  66.   if (!sem_ok)
  67.     {
  68.       sem_ok = 1;
  69.       InitSemaphore(&ss);
  70.     }
  71.  
  72.   ObtainSemaphore(&ss);
  73. #endif
  74.  
  75. #if 0
  76.   while (!(*(unsigned short *)0xdff016 & (1 << 8))) ;
  77.   while ((*(unsigned short *)0xdff016 & (1 << 8))) ;
  78. #endif
  79.  
  80.   if (mp = myFindPort("debug.port"))
  81.     {
  82.       op=CreatePort(0,0);
  83.       buf=AllocMem(255,0);
  84.  
  85.       ms[0].mn_ReplyPort = op;
  86.  
  87.       sprintf(buf, fmt, a0,a1,a2,a3,a4,a5,a6,a7);
  88.       *(char **)&ms[1] = buf;
  89.   
  90.       PutGetMsg(mp, op, &ms[0]);
  91.       DeletePort(op);
  92.       FreeMem(buf,255);
  93.     }
  94.  
  95. #if 0
  96.   ReleaseSemaphore(&ss);
  97. #endif
  98. }
  99. #endif
  100.  
  101. void
  102. print_char()
  103. {
  104.   asm volatile ("moveb d0,a3@+");
  105. }
  106.  
  107. void
  108. sprintf(char *buf, char *fmt, long arg)
  109. {
  110.   RawDoFmt (fmt, &arg, print_char, buf);
  111. }
  112.